package com.infore.airsupervise.ui.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.beardedhen.androidbootstrap.AwesomeTextView;
import com.beardedhen.androidbootstrap.BootstrapText;
import com.beardedhen.androidbootstrap.api.attributes.BootstrapBrand;
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand;
import com.beardedhen.androidbootstrap.font.FontAwesome;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.infore.airsupervise.R;
import com.infore.airsupervise.app.Constants;
import com.infore.airsupervise.app.StatusConst;
import com.infore.airsupervise.bean.MissionE;
import com.infore.airsupervise.biz.MissionBiz;
import com.infore.airsupervise.biz.impl.MissionBizImpl;
import com.infore.airsupervise.http.OnServerResponseListener;
import com.infore.airsupervise.ui.widget.ItemDecoration1px;
import com.infore.airsupervise.ui.widget.refresh.swipetoloadlayout.OnLoadMoreListener;
import com.infore.airsupervise.ui.widget.refresh.swipetoloadlayout.OnRefreshListener;
import com.infore.airsupervise.ui.widget.refresh.swipetoloadlayout.SwipeToLoadLayout;
import com.infore.airsupervise.utils.JumpUtil;
import com.infore.airsupervise.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 执法记录列表
 *
 * @作者: dingxinlin
 * @创建时间: 2017/4/14 10:31
 */
public class LawRecordListActivity
        extends BaseTitleBarActivity
        implements OnRefreshListener, OnLoadMoreListener {

    @BindView(R.id.swipe_target)
    RecyclerView swipeTarget;
    @BindView(R.id.swipeToLoadLayout)
    SwipeToLoadLayout swipeToLoadLayout;

    private String mnStr;

    private BaseQuickAdapter<MissionE, BaseViewHolder> quickAdapter;
    private List<MissionE> datas = new ArrayList<>();

    private MissionBiz missionBiz;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_law_record_list);
        ButterKnife.bind(this);

        mnStr = getIntent().getStringExtra(Constants.INTENT_STR_KEY);
        missionBiz = new MissionBizImpl();

        initView();
    }

    private void initView() {
        title.setText("执法记录列表");
        rightMenu.setVisibility(View.GONE);

        if (mnStr == null || mnStr.isEmpty()) {
            ToastUtil.showLong(ctx, "Intent参数传递失败");
            return;
        }

        // 刷新、加载布局
        swipeToLoadLayout.setOnRefreshListener(this);
        swipeToLoadLayout.setOnLoadMoreListener(this);
        swipeToLoadLayout.post(new Runnable() {
            @Override
            public void run() {
                swipeToLoadLayout.setRefreshing(true);
            }
        });

        quickAdapter = new BaseQuickAdapter<MissionE, BaseViewHolder>(R.layout.item_current_mission, datas) {
            @Override
            protected void convert(BaseViewHolder helper, MissionE item) {
                helper.setText(R.id.tv_mission_title,item.getTitle())
                        .setText(R.id.tv_mission_type,item.getMissionType())
                        .setText(R.id.tv_mission_content,item.getIssueTime());
                AwesomeTextView tv_status =helper.getView(R.id.tv_mission_status);
                BootstrapText bText = new BootstrapText.Builder(ctx)
                        .addFontAwesomeIcon(FontAwesome.FA_CHECK_CIRCLE_O).build();
                tv_status.setBootstrapText(bText);
                tv_status.setBootstrapBrand(DefaultBootstrapBrand.SUCCESS);
            }
        };

        //点击事件
        swipeTarget.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {

            }
        });

        quickAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_LEFT);
        quickAdapter.isFirstOnly(false);

        // 设置Recycler
        swipeTarget.setLayoutManager(new LinearLayoutManager(this));
        swipeTarget.addItemDecoration(new ItemDecoration1px(ctx, ItemDecoration1px.VERTICAL_LIST));
        swipeTarget.setAdapter(quickAdapter);


    }

    @Override
    public void onRefresh() {

    }

    @Override
    public void onLoadMore() {
        swipeToLoadLayout.setLoadingMore(false);
    }

    /**
     * 获取执法记录数据
     */
    private void getLawRecordDatas() {

    }
}
